package desktop;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.util.List;

class ChangeStyle extends JFrame {
    ChangeStyle(List<Screen> screens, List<ScoreTable> scoreTables){
        JTabbedPane tabbedPane = new JTabbedPane();
        for(int i=1;i<=screens.size();i++)
            tabbedPane.addTab("计分屏"+i,style1(screens.get(i-1)));
        tabbedPane.addTab("裁判盒",style2(scoreTables));

        this.add(tabbedPane);
        this.setTitle("显示设置");
        this.setSize(480,200);
        this.setResizable(false);
        this.setVisible(true);
    }

    private JPanel style1(Screen screen){ //计分屏
        JPanel jPanel = new JPanel();
        jPanel.setLayout(new GridLayout(3,2));

        JLabel jLabel_title = new JLabel("标题字体：");
        jPanel.add(jLabel_title);
        JSlider slider_title = new JSlider(0, 100);
        slider_title.setMajorTickSpacing(10);
        slider_title.setMinorTickSpacing(5);
        slider_title.setPaintLabels(true);
        slider_title.setPaintTicks(true);
        slider_title.setValue(screen.getFontSize_title());
        slider_title.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                screen.setFontSize_title(slider_title.getValue());
            }
        });
        jPanel.add(slider_title);

        JLabel jLabel_team = new JLabel("队名字体：");
        jPanel.add(jLabel_team);
        JSlider slider_team = new JSlider(0, 100);
        slider_team.setMajorTickSpacing(10);
        slider_team.setMinorTickSpacing(5);
        slider_team.setPaintLabels(true);
        slider_team.setPaintTicks(true);
        slider_team.setValue(screen.getFontSize_team());
        slider_team.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                screen.setFontSize_team(slider_team.getValue());
            }
        });
        jPanel.add(slider_team);

        JLabel jLabel_table = new JLabel("表格字体：");
        jPanel.add(jLabel_table);
        JSlider slider_table = new JSlider(0, 100);
        slider_table.setMajorTickSpacing(10);
        slider_table.setMinorTickSpacing(5);
        slider_table.setPaintLabels(true);
        slider_table.setPaintTicks(true);
        slider_table.setValue(screen.getFontSize_score());
        slider_table.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                screen.setFontSize_score(slider_table.getValue());
            }
        });
        jPanel.add(slider_table);

        return jPanel;
    }

    private JPanel style2(final List<ScoreTable> scoreTables){ //裁判盒
        JPanel jPanel = new JPanel();
        jPanel.setLayout(new GridLayout(2,1));
        JLabel jLabel_title = new JLabel("表格字体大小：");
        JSlider slider = new JSlider(0,100);
        slider.setMajorTickSpacing(10);
        slider.setMinorTickSpacing(5);
        slider.setPaintLabels(true);
        slider.setPaintTicks(true);
        slider.setValue(scoreTables.get(0).getFontSize());
        slider.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                for(ScoreTable scoreTable:scoreTables)
                    scoreTable.setFontSize(slider.getValue());
            }
        });
        jPanel.add(jLabel_title);
        jPanel.add(slider);

        return jPanel;
    }
}
